<?php

namespace App\Providers;

use Carbon\Carbon;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
use Laravel\Passport\Passport;
use App\Extensions\Md5eloquentProviders;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();


        $this->app['auth']->provider('md5eloquent', function ($app, $config) {
            return new Md5eloquentProviders($this->app['hash'], $config['model']);
        });




        Route::group(['middleware' => 'oauth.providers'], function () {
            Passport::routes(
                function($routeRegistrar){
                    $routeRegistrar->all();
                },
                [
                    'prefix' => 'api/oauth',
                    'namespace' => '\Laravel\Passport\Http\Controllers',
                ]
            );

//            Passport::routes(function ($router) {
//                return $router->forAccessTokens();
//            });

        });

        //token过期时间(100分钟)
        Passport::tokensExpireIn(Carbon::now()->addMinute(100));
        //refresh token过期时间(30天)
        Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));

        //令牌作用域
        Passport::tokensCan(config('scope'));
    }
}
